<template>
  <div class="my_data">
    <header-com title="我的数据" moduleName="match"></header-com>
    <my-tab v-on:childByValue="childByValue"></my-tab>
    <shoose-time v-on:shooseTime="shooseTime"></shoose-time>
    <my-count v-if="shows==1 && aces_a" :aces_a="aces_a" :aces_b="aces_b" :shows="show"></my-count>
    <data-view v-if="shows==2 && aces_b" :aces_a="aces_a" :aces_b="aces_b" :name="name_b"></data-view>
  </div>
</template>
<script>
import shooseTime from "./components/shooseTime.vue";
import myCount from "./components/count.vue";
import dataView from "./components/dataView.vue";
import myTab from "./components/my_tab.vue";
import { mapGetters, mapState } from "vuex";
export default {
  name: "my_datach",
  components: {
    shooseTime,
    dataView,
    myTab,
    myCount
  },
  data() {
    return {
      shows: 1,
      time: "",
      selectedValue: "",
      selectedEndValue: "",
      user_id_b: 17361,
      aces_a: [],
      aces_b: [],
      show: true,
      name_b: ""
    };
  },
  computed: {
    ...mapGetters(["SET_USERINFO"]),
    getCurrentDate() {
      let date = new Date();
      let getYear = date.getFullYear();
      let getMonth = date.getMonth() + 1;
      let getDate = date.getDate();
      if (getMonth < 10) getMonth = `0${getMonth}`;
      if (getDate < 10) getDate = `0${getDate}`;
      let toDay = `${getYear}-${getMonth}-${getDate}`;
      return toDay;
    },
    getAfterYearDate() {
      let date = new Date();
      let getYear = date.getFullYear() - 1;
      let getMonth = date.getMonth() + 1;
      let getDate = date.getDate();
      if (getMonth < 10) getMonth = `0${getMonth}`;
      if (getDate < 10) getDate = `0${getDate}`;
      let toDay = `${getYear}-${getMonth}-${getDate}`;
      return toDay;
    }
  },
  mounted() {
    this.selectedValue = this.getAfterYearDate;
    this.selectedEndValue = this.getCurrentDate;
    this.count();
    this.countNum();
  },
  methods: {
    countNum() {
      var hm = document.createElement("script");
      hm.src = "https://hm.baidu.com/hm.js?4e574c2aad8167d274180b41667c059f";
      var s = document.getElementsByTagName("script")[0];
      s.parentNode.insertBefore(hm, s);
    },
    childByValue(childValue) {
      this.shows = childValue;
      this.showData();
    },
    showData() {},
    shooseTime(con) {
      this.selectedValue = con.start;
      this.selectedEndValue = con.end;
      this.user_id_b = con.userId;
      this.name_b = con.name;
      this.count();
    },
    count() {
      var params = new URLSearchParams();
      params.append("start_time", this.selectedValue);
      params.append("end_time", this.selectedEndValue);
      params.append("type", 0);
      params.append("user_id_b", this.user_id_b);
      this.$axios
        .post("/mobile/v1/PersonalCenter/skill_stat", params)
        .then(res => {
          if ((res.data.code = 2000)) {
            if (res.data.data == "") {
              this.show = false;
            } else {
              this.show = true;
              this.aces_a = res.data.data[0];
              this.aces_b = res.data.data[1];
            }
          }
        })
        .catch(res => {});
    }
  }
};
</script>
